Imports System
Imports System.Collections.Generic
Imports ASPNET.StarterKit.DataAccessLayer

Namespace ASPNET.StarterKit.BusinessLogicLayer

	Public Class UserTotalDurationReport

		Private _TotalDuration As Decimal
		Private _UserName As String

		Public Sub New(ByVal reportTotalDuration As Decimal, ByVal reportUserName As String)

			If reportTotalDuration < DefaultValues.GetDurationMinValue() Then
				Throw New ArgumentOutOfRangeException("totalDuration")
			End If

			If String.IsNullOrEmpty(reportUserName) Then
				Throw New NullReferenceException("userName")
			End If

			Me._TotalDuration = reportTotalDuration
			Me._UserName = reportUserName

		End Sub

		Public ReadOnly Property TotalDuration() As Decimal

			Get
				Return Me._TotalDuration
			End Get

		End Property

		Public ReadOnly Property UserName() As String

			Get
				If String.IsNullOrEmpty(Me._UserName) Then
					Return String.Empty
				Else
					Return Me._UserName
				End If
			End Get

		End Property

		Public Shared Function GetUserReportsByUserName(ByVal reportUserName As String) As List(Of UserTotalDurationReport)

			If String.IsNullOrEmpty(reportUserName) Then
				Return New List(Of UserTotalDurationReport)()
			End If

			Return DataAccessHelper.GetDataAccess().GetUserReportsByUserName(reportUserName)

		End Function

		Public Shared Function GetUserReportsByUserNames(ByVal userNames As String) As List(Of UserTotalDurationReport)

			If String.IsNullOrEmpty(userNames) Then
				Return New List(Of UserTotalDurationReport)()
			End If

			Dim separator As Char() = New Char() {","c}
			Dim substrings As String() = userNames.Split(separator)
			Dim list As New List(Of UserTotalDurationReport)()

			For Each str As String In substrings
				If Not String.IsNullOrEmpty(str) Then
					Dim tempList As List(Of UserTotalDurationReport) = UserTotalDurationReport.GetUserReportsByUserName(str)
					For Each userReport As UserTotalDurationReport In tempList
						list.Add(userReport)
					Next userReport
				End If
			Next str

			Return list

		End Function

	End Class

End Namespace

